package org.ku.hero.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.ku.hero.api.protocol.Command;
import org.ku.hero.api.protocol.Const;
import org.ku.hero.api.protocol.Packet;

/**
 * TCP链路建立成功通道激活时发送登录请求
 */
public class LoginAuthReqHandler extends ChannelInboundHandlerAdapter {

    /**
     * 通道激活 发送登录请求
     * @param ctx
     * @throws Exception
     */
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        ctx.writeAndFlush(buildLoginReq());
    }

    /**
     * 读取返回值
     * @param ctx
     * @param msg
     * @throws Exception
     */
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        final Packet packet = (Packet)msg;
        if (Command.toCmd(packet.getCmd()) == Command.VEHICLE_LOGIN){
            if (packet.getAck() == Const.ACK_SUCC){
                //登录成功


            }else {
                //登录失败

                return;
            }
        }

        ctx.fireChannelRead(msg);
    }

    private Packet buildLoginReq() {

        return null;
    }


}
